home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / windes.zip / DESTEST.C next >
C/C++ Source or Header  |  1993-07-07  |  2KB  |  48 lines

  1. /* DESTEST.C - validates Data Encryption Standard (DES) Algorithm */
  2.  
  3. #include <windows.h>
  4. #include <memory.h>
  5. #include <stdio.h>
  6. #include "windes.h"    /* DES function prototypes */
  7.  
  8. /* size of standard DES block, in bits */
  9. #define    BITSZ    (64)
  10. /* size of standard DES block, in bytes */
  11. #define    BLKSZ    (8)
  12. /* how many standard DES blocks defined in ANSI X9.9 Appendix B */
  13. #define    X99MX    (4)
  14.  
  15. void main(void)
  16. {
  17. //    static BYTE vecbits[BLKSZ] = { 0x73,0x4c,0x51,0xd9,0x70,0xf2,0x1a,0x6e };
  18.     /* for validation, keybits and patterns taken from ANSI X9.9 Appendix B */
  19.     static BYTE keybits[BLKSZ] = { 0xe6,0xa1,0x2f,0x07,0x9d,0x15,0xc4,0x37 };
  20.     static BYTE pattern[X99MX][BLKSZ] = {
  21.         { 0x0a,0x20,0x20,0x20,0x54,0x4f,0x20,0x59 },
  22.         { 0x51,0x44,0x2d,0x38,0x30,0x20,0x30,0x37 },
  23.         { 0x54,0x4f,0x20,0x59,0x4f,0x55,0x52,0x20 },
  24.         { 0x51,0x44,0x2d,0x38,0x30,0x20,0x30,0x37 }
  25.     };
  26.     BYTE results[X99MX*BLKSZ], clrtext[X99MX*BLKSZ];
  27.     WORD i, j;
  28.  
  29.     for (i = 0; i < X99MX; i++)
  30.     {
  31.     DesEnCrypt((LPBYTE) keybits,(LPBYTE) pattern[i],(LPBYTE) results, 1);
  32.     DesDeCrypt((LPBYTE) keybits,(LPBYTE) results,(LPBYTE) clrtext, 1);
  33.         printf(
  34.     "ECB %02x%02x%02x%02x%02x%02x%02x%02x -> %02x%02x%02x%02x%02x%02x%02x%02x \
  35. -> %02x%02x%02x%02x%02x%02x%02x%02x\n",
  36.             pattern[i][0], pattern[i][1], pattern[i][2], pattern[i][3],
  37.             pattern[i][4], pattern[i][5], pattern[i][6], pattern[i][7],
  38.             results[0], results[1], results[2], results[3],
  39.             results[4], results[5], results[6], results[7],
  40.             clrtext[0], clrtext[1], clrtext[2], clrtext[3],
  41.             clrtext[4], clrtext[5], clrtext[6], clrtext[7] );
  42.     }
  43.     printf("\n");
  44.  
  45. } /* main () */
  46.  
  47. /* end of source */
  48.